<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">

<head th:include="include :: snow_header"></head>
<body class="gray-bg">
    <div class="container-div">
		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true"  style="white-space:nowrap"></table>
		</div>
        <div class="form-group">
            <div class="form-control-static col-sm-offset-9">
                <button onclick="release()" type="submit" class="btn btn-primary">提交</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
    </div>
    <div th:include="include :: snow_footer"></div>
    <script th:inline="javascript">
        var releaseFlag = [[${@permission.hasPermi('module:application:edit')}]];
        var configProfileType = [[${@dict.getType('config_profile_type')}]];
        var configServerType = [[${@dict.getType('config_server_type')}]];
        var prefix = ctx + "module/group/release";

        var snowTable=$.snowBootstrap.init();

        $(function() {

            var options = {
                url: prefix + "/list?configGroupId="+[[${configGroupId}]],
                modalName: "引用配置组的应用",
                pagination:true,
                pageSize:999,
                pageList:[999],
                columns: [{
		            checkbox: true
		        },
                {
                    field : 'configApplicationId',
                    title : '应用ID'
                },
                {
                    field : 'appName',
                    title : '应用名称'
                },
                {
                    field : 'description',
                    title : '描述'
                },
				{
					field : 'ipv4', 
					title : 'IP地址' 
				},
				{
					field : 'profileType', 
					title : '应用环境',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(configProfileType, value);
                    }
				},
                {
                    field : 'serverType',
                    title : '服务类型' ,
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(configServerType, value);
                    }
                },
				{
					field : 'remark', 
					title : '备注' 
				},
				// {
				// 	field : 'status',
				// 	title : '状态'
				// },
				{
					field : 'modify', 
					title : '是否修改' 
				},
				{
					field : 'maxVersion', 
					title : '最高版本号' 
				},
				{
					field : 'releaseVersion',
					title : '已发布版本'
				},
                // {
                //     field : 'createBy',
                //     title : '创建者'
                // },
                // {
                //     field : 'createTime',
                //     title : '创建时间'
                // },
                // {
                //     field : 'updateBy',
                //     title : '更新者'
                // },
                // {
                //     field : 'updateTime',
                //     title : '更新时间'
                // },
		        ]
            };
            snowTable.tableInit(options);
        });
        
        function release() {
            var rows = $.common.isEmpty(snowTable._option.id) ? snowTable.selectFirstColumns() : snowTable.selectColumns(snowTable._option.id);
            var appNames = snowTable.selectColumns("appName");
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var data = {
                "configGroupId":[[${configGroupId}]],
                "appIds": rows.join()
            };
            console.log(data);
            var url = prefix + "/toApplication";
            snowTable.operateSubmit(url, "post", "json", data,function(result){
                console.log("result=",result);
                if (result.code == 0) {


                    $.modal.closeLoading();
                    layer.confirm("已成功推送至应用,是否现在发布?", {
                        icon: 3,
                        title: "系统提示",
                        btn: ['一键发布','打开所有应用', '取消'],
                        btnclass: ['btn btn-primary', 'btn btn-danger'],
                    }, function (index) {
                        layer.close(index);
                        var url = ctx + "module/applicationProperty" + "/release";
                        var data = {"ids": rows.join()};
                        snowTable.operateSubmit(url, "post", "json", data,function (res) {
                            if (res.code == 0) {
                                $.modal.alertConfirm({
                                    content:res.msg,
                                    callBack:function () {
                                    $.modal.close();
                                }});
                            }else{
                                $.modal.alertConfirm(res.msg,function () {
                                    $.modal.close();
                                });
                            }
                        });

                    },function (index) {
                        layer.close(index);
                        $.each(rows, function(i,row){
                             var url= ctx + "module/application/detail/"+row;
                            var appName=appNames[i];
                             var titleName="应用属性["+appName+"]";
                            console.log("row=",row,titleName);
                            // var topWindow = $(window.parent.parent.document);
                            // createMenuItem(url, titleName,topWindow);
                            openNewWindow(url);
                            console.log("createMenuItem");
                        });
                        $.modal.close();
                    });


                }else{
                    console.log("result.msg=",result.msg);
                    $.modal.confirm(result.msg,function () {
                        $.modal.close();
                    });
                }
            });

        }


    </script>
</body>
</html>